## Panel Estimates

# multiplier <- 1/100 # this only matters to Ace, as we wanna use the scale adopted by the original study
CI <- .95
CI_alt <- .90
se.method <- "bootstrap"


# West --------------------------------------------------------------------
# pre-define some parameters
data <- btw_west

## allowing for treatment reversal
# get all the estimation results. THIS STEP TAKES A LONG TIME TO RUN
results_greens_west_entry_ci95 <- list()
for (i in 1:length(greens_west_entry)) {
    set.seed(221113)
    # calling the "PanelEstimate()"
    results <- PanelEstimate(
        number.iterations = 1000,
        se.method = se.method,
        confidence.level = CI,
        pooled = F,
        data = data, sets = greens_west_entry[[i]])  
    
    P <- results$estimates
    CIs <- as.numeric(summary(results)$summary[,3:4, drop = F])
    #}
    L <- CIs[1]
    U <- CIs[2]
    results_greens_west_entry_ci95[[i]] <- list("P" = P, "L" = L, "U" = U, "CI" = CI)
    
}

names(results_greens_west_entry_ci95) <- names(greens_west_entry)

### 90 CI

results_greens_west_entry_ci90 <- list()
for (i in 1:length(greens_west_entry)) {
    set.seed(221113)
    # calling the "PanelEstimate()"
    results <- PanelEstimate(
        number.iterations = 1000,
        se.method = se.method,
        confidence.level = CI_alt,
        pooled = F,
        data = data, sets = greens_west_entry[[i]])  
    
    P <- results$estimates
    CIs <- as.numeric(summary(results)$summary[,3:4, drop = F])
    #}
    L <- CIs[1]
    U <- CIs[2]
    results_greens_west_entry_ci90[[i]] <- list("P" = P, "L" = L, "U" = U, "CI" = CI_alt)
    
}


names(results_greens_west_entry_ci90) <- names(greens_west_entry)






# east --------------------------------------------------------------------
# pre-define some parameters
data <- btw_east

## allowing for treatment reversal
# get all the estimation results. THIS STEP TAKES A LONG TIME TO RUN
results_greens_east_entry <- list()
for (i in 1:length(greens_east_entry)) {
    set.seed(221113)
    # calling the "PanelEstimate()"
    results <- PanelEstimate(#inference = "bootstrap", 
        number.iterations = 1000,
        se.method = se.method,
        data = data, sets = greens_east_entry[[i]])  
    
    P <- results$estimates
    CIs <- as.numeric(summary(results)$summary[,3:4, drop = F])
    #}
    L <- CIs[1]
    U <- CIs[2]
    results_greens_east_entry[[i]] <- list("P" = P, "L" = L, "U" = U)
    
}



names(results_greens_east_entry) <- names(greens_east_entry)

save.image(file='data/tmp/PanelMatch_temp2.RData')

